package com.come4loves.core.result;

import io.netty.channel.ChannelFutureListener;

import com.come4loves.core.comunicate.protocol.StatusCode;

public class ResultFuture<T extends ChannelFutureListener> {
	/**
	 * 结果码
	 */
	public short statusCode = StatusCode.SUCCESS;
	
	private T listener;
	
	public T getListener() {
		return listener;
	}
	
	public void setListener(
			T listener) {
		this.listener = listener;
	}
	
	public static <T extends ChannelFutureListener> ResultFuture<T> sucess(T listener) {
		ResultFuture<T> res = new ResultFuture<T>();
		res.listener = listener;
		res.statusCode = StatusCode.SUCCESS;
		return res;
	}
	
	public static <T extends ChannelFutureListener> ResultFuture<T> valueOf(short statusCode) {
		ResultFuture<T> res = new ResultFuture<T>();
		res.statusCode = statusCode;
		return res;
	}
	
	public boolean isFail() {
		return statusCode != StatusCode.SUCCESS;
	}
	
	public boolean isOk() {
		return statusCode == StatusCode.SUCCESS;
	}
}
